Best JavaScript code snippet using argos
log_sync_utils.js
Source:log_sync_utils.js
1(function(){2 var ref$, get_log_names, getInterventionLogCollection, get_current_collections, list_collections_to_sync, getCollection, get_user_id, get_install_id, post_json, sleep, gexport, gexport_module, chrome_manifest, habitlab_version, developer_mode, unofficial_version, start_syncing_all_data, stop_syncing_all_data, upload_log_item_to_server, sync_unsynced_logs, log_syncing_active, start_syncing_all_logs, stop_syncing_all_logs, make_item_synced_in_collection, upload_collection_item_to_server, sync_unsynced_items_in_db_collection, db_syncing_active, start_syncing_all_db_collections, stop_syncing_all_db_collections, out$ = typeof exports != 'undefined' && exports || this;3 ref$ = require('libs_backend/log_utils'), get_log_names = ref$.get_log_names, getInterventionLogCollection = ref$.getInterventionLogCollection;4 ref$ = require('libs_backend/db_utils'), get_current_collections = ref$.get_current_collections, list_collections_to_sync = ref$.list_collections_to_sync, getCollection = ref$.getCollection;5 ref$ = require('libs_backend/background_common'), get_user_id = ref$.get_user_id, get_install_id = ref$.get_install_id;6 post_json = require('libs_backend/ajax_utils').post_json;7 sleep = require('libs_common/common_libs').sleep;8 ref$ = require('libs_common/gexport'), gexport = ref$.gexport, gexport_module = ref$.gexport_module;9 if ((typeof chrome != 'undefined' && chrome !== null ? (ref$ = chrome.runtime) != null ? ref$.getManifest : void 8 : void 8) != null) {10 chrome_manifest = chrome.runtime.getManifest();11 habitlab_version = chrome_manifest.version;12 developer_mode = chrome_manifest.update_url == null;13 unofficial_version = chrome.runtime.id !== 'obghclocpdgcekcognpkblghkedcpdgd';14 } else {15 habitlab_version = 'test';16 developer_mode = true;17 unofficial_version = true;18 }19 out$.start_syncing_all_data = start_syncing_all_data = function(){20 if (localStorage.getItem('allow_logging') !== 'true') {21 dlog('logging disabled, not syncing data');22 return;23 }24 start_syncing_all_logs();25 return start_syncing_all_db_collections();26 };27 out$.stop_syncing_all_data = stop_syncing_all_data = function(){28 stop_syncing_all_db_collections();29 return stop_syncing_all_logs();30 };31 upload_log_item_to_server = async function(name, data){32 var logging_server_url, collection, upload_successful, response, e;33 if (localStorage.getItem('local_logging_server') === 'true') {34 logging_server_url = 'http://localhost:5000/';35 } else {36 logging_server_url = 'https://habitlab.herokuapp.com/';37 }38 collection = (await getInterventionLogCollection(name));39 data = import$({}, data);40 data.logname = name;41 upload_successful = true;42 try {43 response = (await post_json(logging_server_url + 'addtolog', data));44 if (response.success) {45 (await collection.where('id').equals(data.id).modify({46 synced: 147 }));48 } else {49 upload_successful = false;50 dlog('response from server was not successful in upload_log_item_to_server');51 dlog(response);52 dlog(data);53 }54 } catch (e$) {55 e = e$;56 upload_successful = false;57 dlog('error thrown in upload_log_item_to_server');58 dlog(e);59 dlog(data);60 dlog(name);61 }62 return upload_successful;63 };64 out$.sync_unsynced_logs = sync_unsynced_logs = async function(name){65 var collection, num_unsynced, unsynced_items, all_successful, i$, len$, x, item_upload_success;66 collection = (await getInterventionLogCollection(name));67 num_unsynced = (await collection.where('synced').equals(0).count());68 if (num_unsynced === 0) {69 return true;70 }71 dlog('syncing logs ' + name + ' num_unsynced is: ' + num_unsynced);72 unsynced_items = (await collection.where('synced').equals(0).toArray());73 all_successful = true;74 for (i$ = 0, len$ = unsynced_items.length; i$ < len$; ++i$) {75 x = unsynced_items[i$];76 item_upload_success = (await upload_log_item_to_server(name, x));77 if (!item_upload_success) {78 all_successful = false;79 return false;80 }81 }82 return all_successful;83 };84 log_syncing_active = false;85 out$.start_syncing_all_logs = start_syncing_all_logs = async function(){86 var log_names, i$, len$, logname, all_successful;87 if (log_syncing_active) {88 dlog('log_syncing already active');89 return;90 }91 log_syncing_active = true;92 while (log_syncing_active) {93 log_names = (await get_log_names());94 for (i$ = 0, len$ = log_names.length; i$ < len$; ++i$) {95 logname = log_names[i$];96 if (!log_syncing_active) {97 return;98 }99 all_successful = (await sync_unsynced_logs(logname));100 if (!all_successful) {101 dlog('error during logs syncing, pausing 120 seconds: ' + logname);102 (await sleep(120000));103 }104 }105 (await sleep(1000));106 }107 };108 out$.stop_syncing_all_logs = stop_syncing_all_logs = function(){109 return log_syncing_active = false;110 };111 make_item_synced_in_collection = async function(collection_name, item){112 var collection, schema, primary_key, query;113 collection = (await getCollection(collection_name));114 schema = get_current_collections()[collection_name];115 primary_key = schema.split(',')[0];116 if (primary_key === 'key') {117 query = item.key;118 } else if (primary_key === '[key+key2]') {119 query = [item.key, item.key2];120 } else {121 throw new Error('collection has primary key that we do not handle: ' + collection_name);122 }123 return (await collection.where(primary_key).equals(query).and(function(x){124 return x.timestamp === item.timestamp;125 }).modify({126 synced: 1127 }));128 };129 upload_collection_item_to_server = async function(name, data){130 var logging_server_url, collection, upload_successful, response, e;131 if (localStorage.getItem('local_logging_server') === 'true') {132 logging_server_url = 'http://localhost:5000/';133 } else {134 logging_server_url = 'https://habitlab.herokuapp.com/';135 }136 collection = (await getCollection(name));137 data = import$({}, data);138 data.userid = (await get_user_id());139 data.install_id = (await get_install_id());140 data.collection = name;141 data.habitlab_version = habitlab_version;142 if (developer_mode) {143 data.developer_mode = true;144 }145 if (unofficial_version) {146 data.unofficial_version = chrome.runtime.id;147 }148 upload_successful = true;149 try {150 response = (await post_json(logging_server_url + 'sync_collection_item', data));151 if (response.success) {152 (await make_item_synced_in_collection(name, data));153 } else {154 upload_successful = false;155 dlog('response from server was not successful in upload_collection_item_to_server');156 dlog(response);157 dlog(data);158 }159 } catch (e$) {160 e = e$;161 dlog('error thrown in upload_collection_item_to_server');162 dlog(e);163 upload_successful = false;164 }165 return upload_successful;166 };167 out$.sync_unsynced_items_in_db_collection = sync_unsynced_items_in_db_collection = async function(name){168 var collection, num_unsynced, unsynced_items, all_successful, i$, len$, x, item_upload_success;169 collection = (await getCollection(name));170 num_unsynced = (await collection.where('synced').equals(0).count());171 if (num_unsynced === 0) {172 return true;173 }174 dlog('syncing db items ' + name + ' num_unsynced is: ' + num_unsynced);175 unsynced_items = (await collection.where('synced').equals(0).toArray());176 all_successful = true;177 for (i$ = 0, len$ = unsynced_items.length; i$ < len$; ++i$) {178 x = unsynced_items[i$];179 item_upload_success = (await upload_collection_item_to_server(name, x));180 if (!item_upload_success) {181 all_successful = false;182 return false;183 }184 }185 return all_successful;186 };187 db_syncing_active = false;188 out$.start_syncing_all_db_collections = start_syncing_all_db_collections = async function(){189 var collection_names, infrequently_synced, sync_nums, i$, len$, collection_name, all_successful;190 if (db_syncing_active) {191 dlog('db_syncing already active');192 return;193 }194 db_syncing_active = true;195 collection_names = list_collections_to_sync();196 infrequently_synced = ['seconds_on_domain_per_day', 'seconds_on_domain_per_session', 'custom_measurements_each_day', 'visits_to_domain_per_day'];197 sync_nums = {};198 for (i$ = 0, len$ = infrequently_synced.length; i$ < len$; ++i$) {199 collection_name = infrequently_synced[i$];200 sync_nums[collection_name] = 120;201 }202 while (db_syncing_active) {203 for (i$ = 0, len$ = collection_names.length; i$ < len$; ++i$) {204 collection_name = collection_names[i$];205 if (!db_syncing_active) {206 return;207 }208 if (infrequently_synced.includes(collection_name)) {209 sync_nums[collection_name] += 1;210 if (sync_nums[collection_name] < 120) {211 continue;212 } else {213 sync_nums[collection_name] = 0;214 }215 }216 all_successful = (await sync_unsynced_items_in_db_collection(collection_name));217 if (!all_successful) {218 dlog('error during collection syncing, pausing 1200 seconds: ' + collection_name);219 (await sleep(1200000));220 }221 }222 (await sleep(1000));223 }224 };225 out$.stop_syncing_all_db_collections = stop_syncing_all_db_collections = function(){226 return db_syncing_active = false;227 };228 gexport_module('log_sync_utils', function(it){229 return eval(it);230 });231 function import$(obj, src){232 var own = {}.hasOwnProperty;233 for (var key in src) if (own.call(src, key)) obj[key] = src[key];234 return obj;235 }...
SyncingSubscriptionTest.js
Source:SyncingSubscriptionTest.js
1import {formatters} from 'susyweb-core-helpers';2import SyncingSubscription from '../../../../src/subscriptions/sof/SyncingSubscription';3// Mocks4jest.mock('susyweb-core-helpers');5/**6 * SyncingSubscription test7 */8describe('SyncingSubscriptionTest', () => {9 let syncingSubscription;10 beforeEach(() => {11 syncingSubscription = new SyncingSubscription({}, formatters, {});12 });13 it('constructor check', () => {14 expect(syncingSubscription.isSyncing).toEqual(null);15 expect(syncingSubscription.method).toEqual('syncing');16 expect(syncingSubscription.type).toEqual('sof_subscribe');17 expect(syncingSubscription.options).toEqual(null);18 expect(syncingSubscription.utils).toEqual({});19 expect(syncingSubscription.formatters).toEqual(formatters);20 expect(syncingSubscription.moduleInstance).toEqual({});21 });22 it('onNewSubscriptionItem calls outputSyncingFormatter and emits "changed" event (isSyncing: null)', (done) => {23 const item = {result: {syncing: true}};24 syncingSubscription.on('changed', (subscriptionItem) => {25 expect(subscriptionItem).toEqual(true);26 done();27 });28 syncingSubscription.onNewSubscriptionItem(item);29 expect(formatters.outputSyncingFormatter).toHaveBeenCalledWith(item);30 });31 it('onNewSubscriptionItem calls outputSyncingFormatter and emits "changed" event (isSyncing: true)', (done) => {32 const item = {result: {syncing: false}};33 syncingSubscription.on('changed', (subscriptionItem) => {34 expect(subscriptionItem).toEqual(item.result.syncing);35 done();36 });37 syncingSubscription.isSyncing = true;38 syncingSubscription.onNewSubscriptionItem(item);39 expect(formatters.outputSyncingFormatter).toHaveBeenCalledWith(item);40 });41 it('onNewSubscriptionItem calls outputSyncingFormatter and emits "changed" event (isSyncing: false)', (done) => {42 const item = {result: {syncing: true}};43 syncingSubscription.on('changed', (subscriptionItem) => {44 expect(subscriptionItem).toEqual(item.result.syncing);45 done();46 });47 syncingSubscription.isSyncing = false;48 syncingSubscription.onNewSubscriptionItem(item);49 expect(formatters.outputSyncingFormatter).toHaveBeenCalledWith(item);50 });...
Using AI Code Generation
1var argosy = require('argosy')2var argosyPattern = require('argosy-pattern')3var argosySync = require('argosy-sync')4var argosyService = argosy()5argosyService.use(argosyPattern({role: 'math', cmd: 'sum'}, function (args, callback) {6 console.log(args)7 callback(null, result)8}))9argosyService.use(argosySync({role: 'math', cmd: 'sum'}, function (args, callback) {10 console.log(args)11 callback(null, result)12}))13argosyService.listen(8000)14var argosy = require('argosy')15var argosyPattern = require('argosy-pattern')16var argosyService = argosy()17argosyService.use(argosyPattern({role: 'math', cmd: 'sum'}, function (args, callback) {18 console.log(args)19 callback(null, result)20}))21argosyService.listen(8000)22var argosy = require('argosy')23var argosyPattern = require('argosy-pattern')24var argosySync = require('argosy-sync')25var argosyClient = argosy()26argosyClient.use(argosyPattern({role: 'math', cmd: 'sum'}, function (args, callback) {27 console.log(args)28 callback(null, result)29}))30argosyClient.use(argosySync({role: 'math', cmd: 'sum'}, function (args, callback) {31 console.log(args)32 callback(null, result)33}))34argosyClient.connect(8000)35var client = require('./client')36var test = require('./test')37var sum = client({role: 'math', cmd: 'sum'})38sum({left: 1, right: 2}, function (err, result) {39 console.log(result)40})41test({left: 1, right: 2}, function (err, result) {
Using AI Code Generation
1var argosy = require('argosy')2var receiver = argosy()3var sender = argosy()4receiver.pipe(sender).pipe(receiver)5receiver.accept({role: 'math', cmd: 'sum'}, function (msg, cb) {6 cb(null, {answer: msg.left + msg.right})7})8sender.act({role: 'math', cmd: 'sum', left: 1, right: 2}, function (err, msg) {9})10The callback function passed to act() is called with the following arguments:11The callback function passed to accept() is called with the following arguments:12var argosy = require('argosy')13var receiver = argosy()14var sender = argosy()15receiver.pipe(sender).pipe(receiver)16receiver.accept({role: 'math', cmd: 'sum'}, function (msg) {17 return Promise.resolve({answer: msg.left + msg.right})18})19sender.act({role: 'math', cmd: 'sum', left: 1, right: 2}, function (err, msg) {20})
Using AI Code Generation
1var argosy = require('argosy')2var service = argosy()3service.pipe(argosy.acceptor({ port: 8000 })).pipe(service)4service.accept({ hello: 'world' }, function (msg, cb) {5 cb(null, { hey: 'there' })6})7var argosy = require('argosy')8var service = argosy()9service.pipe(argosy.acceptor({ port: 8000 })).pipe(service)10service.accept({ hello: 'world' }, function (msg, cb) {11 cb(null, { hey: 'there' })12})13var argosy = require('argosy')14var service = argosy()15service.pipe(argosy.acceptor({ port: 8000 })).pipe(service)16service.accept({ hello: 'world' }, function (msg, cb) {17 cb(null, { hey: 'there' })18})19var argosy = require('argosy')20var service = argosy()21service.pipe(argosy.acceptor({ port: 8000 })).pipe(service)22service.accept({ hello: 'world' }, function (msg, cb) {23 cb(null, { hey: 'there' })24})25var argosy = require('argosy')26var service = argosy()27service.pipe(argosy.acceptor({ port: 8000 })).pipe(service)28service.accept({ hello: 'world' }, function (msg, cb) {29 cb(null, { hey: 'there' })30})31var argosy = require('argosy')32var service = argosy()33service.pipe(argosy.acceptor({ port: 8000 })).pipe(service)34service.accept({ hello: 'world' }, function (msg, cb) {35 cb(null, { hey: 'there' })36})37var argosy = require('argosy')
Using AI Code Generation
1var argosy = require('argosy')()2var sync = require('argosy-pattern/sync')3argosy.accept(sync({4}, function (pattern, cb) {5 cb(null, 'hello ' + pattern.hello)6}))7argosy.pipe(require('argosy-pattern/transport')()).pipe(argosy)8var sync = require('argosy-pattern/sync')(argosy)9sync.hello('world', function (err, result) {10})
Using AI Code Generation
1var argosy = require('argosy')2var sync = require('argosy-sync')3var request = sync(argosy())4request('hello:world', function (err, reply) {5})6var argosy = require('argosy')7var sync = require('argosy-sync')8var request = argosy()9request.pipe(sync(request)).pipe(request)10request.accept({ hello: 'world' }, function (msg, cb) {11 cb(null, 'hello world')12})13### sync(request)
Using AI Code Generation
1var argos = require('argos-sync');2var argosSync = argos.createClient({host: "localhost", port: 6379, password: "password"});3var argos = require('argos');4var argosAsync = argos.createClient({host: "localhost", port: 6379, password: "password"});5var argos = require('argos');6var argosAsync = argos.createClient({host: "localhost", port: 6379, password: "password"});7var result = argosSync.get("key");8console.log(result);9argosAsync.get("key", function(err, result){10 console.log(result);11});12argosAsync.get("key").then(function(result){13 console.log(result);14});15[MIT License](
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!