static PyObject * Bucket__start_timings(pycbc_Bucket *self) { lcb_disable_timings(self->instance); lcb_enable_timings(self->instance); Py_RETURN_NONE; }
/** * Program entry point. * * "monitor" a directory and upload all of the JSON files in that * directory to a couchbase server. * * @param argc argument count * @param argv argument vector */ int main(int argc, char **argv) { const char *spool = default_spool; const char *host = NULL; const char *user = NULL; const char *passwd = NULL; const char *bucket = NULL; int sleep_time = 5; lcb_error_t ret; int cmd; struct option opts[7]; struct lcb_create_st create_options; memset(opts, 0, sizeof(opts)); setup_options(opts); /* Parse command line arguments */ while ((cmd = getopt_long(argc, argv, "s:" /* spool directory */ "h:" /* host */ "u:" /* user */ "p:" /* password */ "b:" /* bucket */ "t:", /* Sleep time */ opts, NULL)) != -1) { switch (cmd) { case 's' : spool = optarg; break; case 'h' : host = optarg; break; case 'u' : user = optarg; break; case 'p' : passwd = optarg; break; case 'b' : bucket = optarg; break; case 't' : sleep_time = atoi(optarg); break; default: fprintf(stderr, "Usage: vacuum [options]\n" "\t-h host\tHostname to connect to (default: localhost:8091)\n" "\t-u user\tUsername to log in with (default: none)\n" "\t-p passwd\tPassword to log in with (default: none)\n" "\t-b name\tName of bucket to connect to (default: default)\n" "\t-v\tEnable verbosity\n" "\t-t sec\tNumber of seconds between each scan (default: 5)\n" "\t-s dir\tLocation of spool directory (default: %s)\n", default_spool); exit(EXIT_FAILURE); } } /* Change working directory to the spool directory */ if (chdir(spool) != 0) { fprintf(stderr, "Failed to enter directory %s: %s\n", spool, strerror(errno)); exit(EXIT_FAILURE); } memset(&create_options, 0, sizeof(create_options)); create_options.v.v0.host = host; create_options.v.v0.user = user; create_options.v.v0.passwd = passwd; create_options.v.v0.bucket = bucket; /* Create the instance to lcb */ ret = lcb_create(&instance, &create_options); if (ret != LCB_SUCCESS) { fprintf(stderr, "Failed to create couchbase instance\n"); exit(EXIT_FAILURE); } /* Set up the callbacks we want */ (void)lcb_set_store_callback(instance, store_callback); (void)lcb_set_error_callback(instance, error_callback); /* Tell libcouchback to connect to the server */ ret = lcb_connect(instance); if (ret != LCB_SUCCESS) { fprintf(stderr, "Failed to connect: %s\n", lcb_strerror(instance, ret)); exit(EXIT_FAILURE); } /* Wait for the server to complete */ lcb_wait(instance); if ((ret = lcb_enable_timings(instance) != LCB_SUCCESS)) { fprintf(stderr, "Failed to enable timings: %s\n", lcb_strerror(instance, ret)); } /* Loop forever and process the spool directory */ while (1) { int ii; int nsec = sleep_time; process_directory(); do { fprintf(stdout, "\rsleeping %d secs before retry..", nsec); fflush(stdout); sleep(1); --nsec; } while (nsec > 0); fprintf(stdout, "\r"); for (ii = 0; ii < 70; ++ii) { fprintf(stdout, " "); } fprintf(stdout, "\r"); fflush(stdout); } return 0; }